import requests
from tools import get_color, get_time
from requestsdata import get_weather, get_token, yiyan

# 请配置好以下信息
appID = "wx7fc8f07702d00b13"  # 微信公众平台的appID
appsecret = "1662e1cd01d627ada201063398ee2b72"  # 微信公众平台的appsecret
templateid = "BZEGNh0g9v59ryE5WlvibgjhkmHPr1gLnWf0iQ5Ofco"  # 微信公众平台的模板消息ID
cityname = "遂宁"  # 需要查询天气地区的名称
city = "101270701"  # 需要查询天气地区的城市代码
users = ["oUDDm5rqV4_RzAhZZq_ccXQLJtCI", "oUDDm5hZftcBo3V1COfigVR6PmtA", "oUDDm5gbxetm8pzm6Wzai1oMkMNQ"]  # 微信公众平台的用户微信号 需要给几个用户推送，就写几个用户的微信号
gotourl = ""  # 单击推送消息需要跳转到的页面
time = '2000-08-27 14:00:00'  # 情侣两个人在一起的开始时间

weather, temp, tempn = get_weather(city)


def send(user):
    url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + get_token(appID, appsecret)
    data = {
        "touser": user,
        "template_id": templateid,
        "url": gotourl,
        "topcolor": "#FF0000",
        "data": {
            "city": {
                "value": cityname,
                "color": get_color()
            },
            "weather": {
                "value": weather,
                "color": get_color()
            },
            "min_temperature": {
                "value": tempn,
                "color": get_color()
            },
            "max_temperature": {
                "value": temp,
                "color": get_color()
            },
            "yiyan": {
                "value": yiyan(),
                "color": get_color()
            },
            "time": {
                "value": get_time(time),
                "color": get_color()
            }
        }
    }
    res = requests.post(url, json=data)
    print(res.text)


for user in users:
    send(user)
